package com.wzs.workbench.service.impl;

import com.wzs.utils.DateTimeUtil;
import com.wzs.workbench.dao.ChapterMapper;
import com.wzs.workbench.domain.Chapter;
import com.wzs.workbench.service.ChapterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ChapterServiceImpl implements ChapterService {

    @Resource
    private ChapterMapper chapterMapper;

    @Override
    public boolean save(Chapter chapter) {

        boolean flag = true;

        String createtime = DateTimeUtil.getSysTime();
        chapter.setCreatetime(createtime);

        int count = chapterMapper.save(chapter);

        if (count!=1){
            flag=false;
        }

        return flag;

    }

    @Override
    public boolean delete(String[] ids) {

        boolean flag = true;

        //删除读者信息
        int count3 = chapterMapper.delete(ids);
        if (count3 != ids.length) {
            flag = false;
        }
        return flag;

    }

    @Override
    public Chapter getChapterAll(String id) {
        return chapterMapper.getChapterAll(id);
    }

    @Override
    public boolean update(Chapter chapter) {
        boolean flag = true;

        String updatetime = DateTimeUtil.getSysTime();
        chapter.setUpdatetime(updatetime);

        //删除读者信息
        int count = chapterMapper.update(chapter);
        if (count != 1) {
            flag = false;
        }
        return flag;
    }
}
